<?php
namespace app\home\controller;

use app\common\controller\Indexbase;
use app\common\model\UserData as cxModel;

class User extends Indexbase {
    /**
     * 单个会员请求，UID
     * @return \think\response\View|void
     */
    public function getOne(){
        //  获取请求
        $getdata = request()->param();
        $getdata = datatrim($getdata);
        if (!isset($getdata['uid']) || empty($getdata['uid'])){
            return $this->error("非法请求");
        }
        //  调用模板
        $parts['mlabel'] = 'user_vitae';
        $temps = $this->temp.'user_vitae.htm';
        require_once APP_PATH . 'common/extend/Label.php';
        //  获取会员数据
        $cxmodel = new cxModel();
        $user = $cxmodel->where('uid',$getdata['uid'])->where('status','1')->find();
        if(empty($user)){
            return $this->error("用户被禁用或不存在");
        }
        $user = $user->toArray();
        if(!empty($user['uicon'])){
            $user['uicon'] = $this->webdb['updir'].'/'.$user['uicon'];
        }
        $user['group_name'] = model('AuthGroup')->where('id',$user['group_id'])->value('title');
        unset($user['upassword']);
        $webs = array(
            'title' => $user['uniname'].'-'.$user['group_name'].'-'.$this->webdb['webname'],
            'keywords' => $this->webdb['webkeywords'],
            'description' => $this->webdb['description'],
        );
        $this->assign([
            'webs' => $webs,
            'getuser' => $user,
        ]);
        return view($temps);
    }

    /**
     *
     */
    public function userList(){
        //  获取请求
        $getdata = request()->param();
        $getdata = datatrim($getdata);
        if (!isset($getdata['group_id']) || empty($getdata['group_id'])){
            return $this->error("非法请求");
        }
        //  调用模板
        $parts['mlabel'] = 'user_list';
        $temps = $this->temp.'user_list.htm';
        require_once APP_PATH . 'common/extend/Label.php';
        $cxmodel = new cxModel();
        $userlist = $cxmodel->where('group_id',$getdata['group_id'])->where('status','1')->order('ujian desc,uregtime desc')->paginate('12',false,['query' => request()->param()])->each(function ($item){
            $item->group_name = model('AuthGroup')->where('id',$item->group_id)->value('title');
            if($item->uicon){
                $item->uicon = $this->webdb['updir'].'/'.$item->uicon;
            }
        });
        $group = model('AuthGroup')->where('id',$getdata['group_id'])->find();
        $pages = $userlist->render();
        if(!empty($userlist)){
            foreach ($userlist as $k => $v){
                unset($v['upassword']);
                $userlist[$k] = $v;
            }
        }
        $webs = array(
            'title' => $this->webdb['webname'],
            'keywords' => $this->webdb['webkeywords'],
            'description' => $this->webdb['description'],
        );
        $this->assign([
            'webs' => $webs,
            'userlist' => $userlist,
            'pages' => $pages,
            'group' => $group,
        ]);
        return view($temps);
    }
}
?>